//
//  YeeRefreshHeader.m
//  MJRefreshExample
//
//  Created by CoderYee on 2017/3/30.
//  Copyright © 2017年 小码哥. All rights reserved.
//

#import "YeeRefreshHeader.h"
#import "JElasticPullToRefreshLoadingViewCircle.h"

@interface YeeRefreshHeader ()

@property(nonatomic,retain)JElasticPullToRefreshLoadingViewCircle *circlrView;

@end

@implementation YeeRefreshHeader

- (void)prepare
{
    [super prepare];
    // 设置控件的高度
    self.mj_h = 54;
    _circlrView=[[JElasticPullToRefreshLoadingViewCircle alloc] init];
    [_circlrView setFrame:CGRectMake(0, 0, 20, 20)];
    [_circlrView setPullProgress:0.3];
    [_circlrView setTintColor:kNavBarThemeColor];
    [self addSubview:_circlrView];

}

#pragma mark 在这里设置子控件的位置和尺寸
- (void)placeSubviews
{
    [super placeSubviews];
    
    _circlrView.center=CGPointMake(self.mj_w * 0.5, 34);
}

#pragma mark 监听scrollView的contentOffset改变
- (void)scrollViewContentOffsetDidChange:(NSDictionary *)change
{
    [super scrollViewContentOffsetDidChange:change];
}

#pragma mark 监听scrollView的contentSize改变
- (void)scrollViewContentSizeDidChange:(NSDictionary *)change
{
    [super scrollViewContentSizeDidChange:change];
    
}

#pragma mark 监听scrollView的拖拽状态改变
- (void)scrollViewPanStateDidChange:(NSDictionary *)change
{
    [super scrollViewPanStateDidChange:change];
    
}

#pragma mark 监听控件的刷新状态
- (void)setState:(MJRefreshState)state
{
    MJRefreshCheckState;
    
    switch (state) {
        case MJRefreshStateIdle:
            [_circlrView stopLoading];
            
            break;
        case MJRefreshStatePulling:
            
            [_circlrView setPullProgress:self.scrollView.contentOffset.y/self.mj_h];

            break;
            
        case MJRefreshStateWillRefresh:
    

        break;
            
        case MJRefreshStateRefreshing:
            
           [_circlrView startAnimating];
            break;
        default:
            break;
    }
}

#pragma mark 监听拖拽比例（控件被拖出来的比例）
- (void)setPullingPercent:(CGFloat)pullingPercent
{
    [super setPullingPercent:pullingPercent];
    [_circlrView setPullProgress: pullingPercent];

}

@end
